package Thread2;

// 使用 Runnable 完成 1 + 2 + 3 + ... + 100
public class Demo38 {
    private static int total = 0;
    public static void main(String[] args) throws InterruptedException {
        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                int sum = 0;
                for (int i = 0; i <= 100 ; i++) {
                    sum += i;
                }
                total = sum;
            }
        };

        Thread t = new Thread(runnable);
        t.start();
        t.join(); // 等待线程执行完毕

        System.out.println("total = " + total);
    }
}
